<template>
    <a-layout>
        <a-layout-header style="background: #fff; padding: 0"/>
        <a-layout-content style="margin: 0 16px">
            <a-breadcrumb style="margin: 16px 0">
                <a-breadcrumb-item>首页</a-breadcrumb-item>
                <a-breadcrumb-item>客户分组列表</a-breadcrumb-item>
            </a-breadcrumb>
            <div class="toolsbar">
                <div style="float: left;margin-left: 10px;margin-top: 10px;">
                    <!--                    <a-button @click="addadmin()" type="primary">新建客户分组</a-button>-->
<!--                    <a-input-group compact>-->
<!--&lt;!&ndash;                        <a-select defaultValue="用户名">&ndash;&gt;-->
<!--&lt;!&ndash;&lt;!&ndash;                            <a-select-option value="username">用户名</a-select-option>&ndash;&gt;&ndash;&gt;-->
<!--&lt;!&ndash;                            &lt;!&ndash;                    <a-select-option value="username">用户名</a-select-option>&ndash;&gt;&ndash;&gt;-->
<!--&lt;!&ndash;                        </a-select>&ndash;&gt;-->
<!--                        <a-input-search @search="onSearch" enterButton style="width: 200px" placeholder="输入医生名字进行查找"/>-->
<!--                        <a-button :loading="loading" @click="start" style="margin-left: 10px" type="primary">-->
<!--                            刷新-->
<!--                        </a-button>-->
<!--                    </a-input-group>-->

                </div>
<!--                <div class="serach_input">-->
<!--                   -->
<!--                </div>-->
            </div>
            <a-row type="flex">
                <a-col :style="{ overflow: 'auto', height: '100vh',}" flex="300px">
                    <a-menu @click="handleClick" mode="vertical" style="width: 100%">
<!--                        {{Doctordata}}-->
                        <a-menu-item :key="items.uid" v-for="(items,indexs) in Doctordata">
                            <a-icon type="mail"/>
                            [{{items.uid}}] {{items.name}}
                        </a-menu-item>

                        <!--                        <a-menu-item key="2">-->
                        <!--                            <a-icon type="calendar" />-->
                        <!--                            Navigation Two-->
                        <!--                        </a-menu-item>-->
                        <!--                        <a-sub-menu key="sub1">-->
                        <!--                            <span slot="title"><a-icon type="appstore" /><span>Navigation Three</span></span>-->
                        <!--                            <a-menu-item key="3">-->
                        <!--                                Option 3-->
                        <!--                            </a-menu-item>-->
                        <!--                            <a-menu-item key="4">-->
                        <!--                                Option 4-->
                        <!--                            </a-menu-item>-->
                        <!--                            <a-sub-menu key="sub1-2" title="Submenu">-->
                        <!--                                <a-menu-item key="5">-->
                        <!--                                    Option 5-->
                        <!--                                </a-menu-item>-->
                        <!--                                <a-menu-item key="6">-->
                        <!--                                    Option 6-->
                        <!--                                </a-menu-item>-->
                        <!--                            </a-sub-menu>-->
                        <!--                        </a-sub-menu>-->
                        <!--                        <a-sub-menu key="sub2">-->
                        <!--                            <span slot="title"><a-icon type="setting" /><span>Navigation Four</span></span>-->
                        <!--                            <a-menu-item key="7">-->
                        <!--                                Option 7-->
                        <!--                            </a-menu-item>-->
                        <!--                            <a-menu-item key="8">-->
                        <!--                                Option 8-->
                        <!--                            </a-menu-item>-->
                        <!--                            <a-menu-item key="9">-->
                        <!--                                Option 9-->
                        <!--                            </a-menu-item>-->
                        <!--                            <a-menu-item key="10">-->
                        <!--                                Option 10-->
                        <!--                            </a-menu-item>-->
                        <!--                        </a-sub-menu>-->
                    </a-menu>

                </a-col>
                <a-divider type="vertical" style="height: 100vh" />
                <a-col flex="auto" style="padding-top: 10px;">
                    <div v-if="this.add.d_uid == 0">
                        请点击左侧医生名字获取分组信息
                    </div>
                    <a-tabs default-active-key="1" @change="callback" style="background-color: white;padding: 10px" v-if="this.add.d_uid != 0">
                        <a-tab-pane key="1" tab="个人">
                            <div><a-button @click="addself()" type="primary">新增私人分组</a-button> <a-button @click="showPunchinDrawer" type="primary">
                                <a-icon type="plus"/>
                                增加打卡项目
                            </a-button></div>
                            <a-table
                                    :columns="group"
                                    :dataSource="Groupinfo.self"
                                    :loading="loading"
                                    :pagination="pagination"
                                    bordered
                                    rowKey="id"
                                    style="margin-top: 10px;"
                            >
                                <template slot="operation" slot-scope="text, index">

                                    <a @click="editself(index)" style="margin-right: 10px">编辑分组</a>
                                    <a @click="delGroup(index)">剔除分组</a>

                                </template>
                            </a-table>
                        </a-tab-pane>
                        <a-tab-pane key="2" tab="合作" force-render>
                            <div><a-button @click="addhas_groups()" type="primary">新增合作分组</a-button></div>
                            <a-table
                                    :columns="group"
                                    :dataSource="Groupinfo.cooperation"
                                    :loading="loading"
                                    :pagination="pagination"

                                    bordered
                                    rowKey="uid"
                                    style="margin-top: 10px;"
                            >
                                <template slot="operation" slot-scope="text, index">

                                    <a @click="edithas_groups(index)" style="margin-right: 10px">编辑分组</a>
                                    <a @click="delGroup(index)">剔除分组</a>

                                </template>
                            </a-table>
                        </a-tab-pane>
<!--                        <a-tab-pane key="3" tab="不知道是啥" force-render>-->
<!--                            {{Groupinfo.has_groups}}-->
<!--                        </a-tab-pane>-->
                    </a-tabs>

                </a-col>
            </a-row>



        </a-layout-content>
        <a-layout-footer style="text-align: center"></a-layout-footer>

        <a-modal @ok="addcoopok" title="新增客户共享分组" v-model="popaddcoop" width="55%">
            <a-form-item :label-col="{ span: 5 }" :wrapper-col="{ span: 18 }" label="客户分组名字">
                <a-input placeholder="请输入登录名" v-model="add.name"/>
            </a-form-item>
            <a-form-item :label-col="{ span: 5 }" :wrapper-col="{ span: 12 }" label="选择医生组">
                <a-button @click="showDoctorDrawer" type="primary">
                    <a-icon type="plus"/>
                    选择医生组
                </a-button>
            </a-form-item>
<!--            {{selectedDoctorRow}}-->
            <a-table
                    :columns="drawer"
                    :dataSource="selectedDoctorRow"
                    :loading="loading"
                    :pagination="pagination"

                    bordered
                    rowKey="id"
            >

                <template slot="sex" slot-scope="text, index" style="text-align: center">
                    <a-tag :color="'green'" v-if="index.sex === 1"><span>男</span></a-tag>
                    <a-tag :color="'red'" v-if="index.sex !== 1">女</a-tag>
                </template>


            </a-table>
            <a-form-item :label-col="{ span: 5 }" :wrapper-col="{ span: 12 }" label="选择医生组">
                <a-button @click="showDrawer" type="primary">
                    <a-icon type="plus"/>
                    选择客户
                </a-button>
            </a-form-item>
<!--            {{selectedRow}}-->
            <a-table
                    :columns="drawer"
                    :dataSource="selectedRow"
                    :loading="loading"
                    :pagination="pagination"

                    bordered
                    rowKey="id"
            >

                <template slot="sex" slot-scope="text, index" style="text-align: center">
                    <a-tag :color="'green'" v-if="index.sex === 1"><span>男</span></a-tag>
                    <a-tag :color="'red'" v-if="index.sex !== 1">女</a-tag>
                </template>


            </a-table>
        </a-modal>
        <a-modal @ok="addselfok" title="新增客户私人分组" v-model="popaddself" width="55%">
            <a-form-item :label-col="{ span: 5 }" :wrapper-col="{ span: 18 }" label="客户分组名字">
                <a-input placeholder="请输入登录名" v-model="add.name"/>
            </a-form-item>
<!--            <a-form-item :label-col="{ span: 5 }" :wrapper-col="{ span: 12 }" label="选择医生组">-->
<!--                <a-button @click="showDrawer" type="primary">-->
<!--                    <a-icon type="plus"/>-->
<!--                    选择医生组-->
<!--                </a-button>-->
<!--            </a-form-item> -->
            <a-form-item :label-col="{ span: 5 }" :wrapper-col="{ span: 12 }" label="选择医生组">
                <a-button @click="showDrawer" type="primary">
                    <a-icon type="plus"/>
                    选择客户
                </a-button>
            </a-form-item>
            <a-table
                    :columns="drawer"
                    :dataSource="selectedRow"
                    :loading="loading"
                    :pagination="pagination"

                    bordered
                    rowKey="id"
            >

                <template slot="sex" slot-scope="text, index" style="text-align: center">
                    <a-tag :color="'green'" v-if="index.sex === 1"><span>男</span></a-tag>
                    <a-tag :color="'red'" v-if="index.sex !== 1">女</a-tag>
                </template>


            </a-table>
        </a-modal>
        <a-modal @ok="editcoopok" title="编辑客户共享分组" v-model="popeditcoop" width="55%">
            <a-form-item :label-col="{ span: 5 }" :wrapper-col="{ span: 18 }" label="客户分组名字">
                <a-input placeholder="请输入登录名" v-model="edit.name"/>
            </a-form-item>
            <a-form-item :label-col="{ span: 5 }" :wrapper-col="{ span: 12 }" label="选择医生组">
                <a-button @click="showDoctorDrawer" type="primary">
                    <a-icon type="plus"/>
                    选择医生组
                </a-button>
            </a-form-item>
<!--            {{selectedDoctorRow}}-->
            <a-table
                    :columns="drawer"
                    :dataSource="selectedDoctorRow"
                    :loading="loading"
                    :pagination="pagination"

                    bordered
                    rowKey="id"
            >

                <template slot="sex" slot-scope="text, index" style="text-align: center">
                    <a-tag :color="'green'" v-if="index.sex === 1"><span>男</span></a-tag>
                    <a-tag :color="'red'" v-if="index.sex !== 1">女</a-tag>
                </template>


            </a-table>
            <a-form-item :label-col="{ span: 5 }" :wrapper-col="{ span: 12 }" label="选择医生组">
                <a-button @click="showDrawer" type="primary">
                    <a-icon type="plus"/>
                    选择客户
                </a-button>
            </a-form-item>
<!--            {{selectedRow}}-->
            <a-table
                    :columns="drawer"
                    :dataSource="selectedRow"
                    :loading="loading"
                    :pagination="pagination"

                    bordered
                    rowKey="id"
            >

                <template slot="sex" slot-scope="text, index" style="text-align: center">
                    <a-tag :color="'green'" v-if="index.sex === 1"><span>男</span></a-tag>
                    <a-tag :color="'red'" v-if="index.sex !== 1">女</a-tag>
                </template>


            </a-table>
        </a-modal>
        <a-modal @ok="editselfok" title="编辑客户私人分组" v-model="popeditself" width="55%">
            <a-form-item :label-col="{ span: 5 }" :wrapper-col="{ span: 18 }" label="客户分组名字">
                <a-input placeholder="请输入登录名" v-model="edit.name"/>
            </a-form-item>
<!--            <a-form-item :label-col="{ span: 5 }" :wrapper-col="{ span: 12 }" label="选择医生组">-->
<!--                <a-button @click="showDrawer" type="primary">-->
<!--                    <a-icon type="plus"/>-->
<!--                    选择医生组-->
<!--                </a-button>-->
<!--            </a-form-item> -->
            <a-form-item :label-col="{ span: 5 }" :wrapper-col="{ span: 12 }" label="选择医生组">
                <a-button @click="showDrawer" type="primary">
                    <a-icon type="plus"/>
                    选择客户
                </a-button>
            </a-form-item>
<!--            {{data}}-->
            <a-table
                    :columns="drawer"
                    :dataSource="selectedRow"
                    :loading="loading"
                    :pagination="pagination"

                    bordered
                    rowKey="id"
            >

                <template slot="sex" slot-scope="text, index" style="text-align: center">
                    <a-tag :color="'green'" v-if="index.sex === 1"><span>男</span></a-tag>
                    <a-tag :color="'red'" v-if="index.sex !== 1">女</a-tag>
                </template>


            </a-table>
        </a-modal>
        <a-drawer
                :closable="false"
                :visible="Doctorvisible"
                @close="onClose"
                title="医生列表"
                width="720"
                style="z-index: 2000"
        >

<!--{{selectedDoctorRowKeys}}-->
            <!--                        {{Doctordata}}-->
            <a-table
                    :columns="drawer"
                    :dataSource="Doctordata"
                    :loading="loading"
                    :pagination="pagination"
                    :row-selection="{ selectedDoctorRowKeys: selectedDoctorRowKeys, onChange: onSelectDoctorChange,type:'radio'}"
                    @change="onChange"
                    bordered
                    rowKey="uid"

            >
                <template slot="sex" slot-scope="text, index" style="text-align: center">
                    <a-tag :color="'green'" v-if="index.sex === 1"><span>男</span></a-tag>
                    <a-tag :color="'red'" v-if="index.sex !== 1">女</a-tag>
                </template>
            </a-table>

            <div
                    :style="{
                      position: 'absolute',
                      bottom: 0,
                      width: '100%',
                      borderTop: '1px solid #e8e8e8',
                      padding: '10px 16px',
                      textAlign: 'right',
                      left: 0,
                      background: '#fff',
                      borderRadius: '0 0 4px 4px',
                    }"
            >
                <a-button @click="onClose" style="marginRight: 8px">
                    取消
                </a-button>
                <a-button @click="onClose" type="primary">
                    提交
                </a-button>
            </div>
        </a-drawer>
        <a-drawer
                :closable="false"
                :visible="visible"
                @close="onClose"
                title="客户列表"
                width="720"
                style="z-index: 2000"
        >


            <!--                        {{Doctordata}}-->
            <a-table
                    :columns="drawer"
                    :dataSource="data"
                    :loading="loading"
                    :pagination="pagination"
                    :row-selection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
                    @change="onChange"
                    bordered
                    rowKey="uid"
            >
                <template slot="sex" slot-scope="text, index" style="text-align: center">
                    <a-tag :color="'green'" v-if="index.sex === 1"><span>男</span></a-tag>
                    <a-tag :color="'red'" v-if="index.sex !== 1">女</a-tag>
                </template>
            </a-table>

            <div
                    :style="{
                      position: 'absolute',
                      bottom: 0,
                      width: '100%',
                      borderTop: '1px solid #e8e8e8',
                      padding: '10px 16px',
                      textAlign: 'right',
                      left: 0,
                      background: '#fff',
                      borderRadius: '0 0 4px 4px',
                    }"
            >
                <a-button @click="onClose" style="marginRight: 8px">
                    取消
                </a-button>
                <a-button @click="onClose" type="primary">
                    提交
                </a-button>
            </div>
        </a-drawer>
        <a-drawer
                :closable="false"
                :visible="Punchinvisible"
                @close="onClose"
                style="z-index: 2000"
                title="打卡列表"
                width="720"
        >

            <!--{{selectedDoctorRowKeys}}-->
            <!--                        {{Doctordata}}-->
            <a-table
                    :columns="patientin"
                    :dataSource="punchindata"
                    :loading="loading"
                    :pagination="pagination"
                    :row-selection="{ selectedDoctorRowKeys: selectedDoctorRowKeys, onChange: onSelectDoctorChange,type:'radio'}"
                    @change="onChange"
                    bordered
                    rowKey="uid"

            >
                <template slot="interval_type" slot-scope="text, index" style="text-align: center">
                    <a-tag :color="'red'" v-if="index.interval_type === -1"><span>不提醒</span></a-tag>
                    <a-tag :color="'green'" v-if="index.interval_type === 1">每天</a-tag>
                    <a-tag :color="'green'" v-if="index.interval_type === 2">每周</a-tag>
                </template>
                <template slot="is_default" slot-scope="text, index" style="text-align: center">
                    <!--                        <a-tag :color="'red'" v-if="index.is_default === -1"><span>不提醒</span></a-tag>-->
                    <a-tag :color="'green'" v-if="index.is_default === 1">默认</a-tag>
                    <a-tag :color="'red'" v-if="index.is_default === 2">非默认</a-tag>
                </template>
                <template slot="status" slot-scope="text, index" style="text-align: center">
                    <a-tag :color="'green'" v-if="index.status === 1"><span>正常</span></a-tag>
                    <a-tag :color="'red'" v-if="index.status !== 1">异常</a-tag>
                </template>
            </a-table>

            <div
                    :style="{
                      position: 'absolute',
                      bottom: 0,
                      width: '100%',
                      borderTop: '1px solid #e8e8e8',
                      padding: '10px 16px',
                      textAlign: 'right',
                      left: 0,
                      background: '#fff',
                      borderRadius: '0 0 4px 4px',
                    }"
            >
                <a-button @click="onClose" style="marginRight: 8px">
                    取消
                </a-button>
                <a-button @click="addObject" type="primary">
                    提交
                </a-button>
            </div>
        </a-drawer>
    </a-layout>

</template>

<script>
    // import moment from "moment";

    import moment from "moment";
    import {Modal} from "ant-design-vue";
    import Storage from "../common/storage";

    const columns = [
        {
            title: "id",
            dataIndex: "id",
            width: "5%",
            scopedSlots: {customRender: "id"}
        },
        // {
        //     title: "用户名",
        //     dataIndex: "login_name",
        //     width: "20%",
        //     scopedSlots: {customRender: "login_name"}
        // },
        {
            title: "名字",
            dataIndex: "name",
            width: "15%",
            scopedSlots: {customRender: "name"}
        },
        {
            title: "状态",
            width: "5%",
            dataIndex: "status",
            scopedSlots: {customRender: "status"}
        },
        {
            title: '操作',
            width: "7%",
            key: 'operation',
            scopedSlots: {customRender: 'operation'}
        },
    ];
    const drawer = [
        {
            title: "uid",
            dataIndex: "uid",
            width: "20%",
            scopedSlots: {customRender: "uid"}
        },
        {
            title: "名字",
            dataIndex: "name",
            scopedSlots: {customRender: "name"}
        },
        {
            title: "性别",
            dataIndex: "sex",
            scopedSlots: {customRender: "sex"}
        },
        {
            title: "联系方式",
            dataIndex: "mobile",
            scopedSlots: {customRender: "mobile"}
        },
        // {
        //     title: '操作',
        //     width: "25%",
        //     key: 'operation',
        //     scopedSlots: {customRender: 'operation'}
        // },
    ];
    const group = [
        {
            title: "uid",
            dataIndex: "id",
            width: "10%",
            scopedSlots: {customRender: "id"}
        },
        {
            title: "名字",
            dataIndex: "name",
            scopedSlots: {customRender: "name"}
        },
        // {
        //     title: "联系方式",
        //     dataIndex: "mobile",
        //     scopedSlots: {customRender: "mobile"}
        // },
        {
            title: '操作',
            width: "25%",
            key: 'operation',
            scopedSlots: {customRender: 'operation'}
        },
    ];
    const patientin = [
        {
            title: "id",
            dataIndex: "id",

            scopedSlots: {customRender: "id"}
        },
        {
            title: "标题",
            dataIndex: "title",

            scopedSlots: {customRender: "title"}
        },
        {
            title: "提醒类型",
            dataIndex: "interval_type",

            scopedSlots: {customRender: "interval_type"}
        },

        {
            title: "重复周期",
            dataIndex: "interval_time",

            scopedSlots: {customRender: "interval_time"}
        },
        {
            title: "默认",
            dataIndex: "is_default",

            scopedSlots: {customRender: "is_default"}
        },
        {
            title: "状态",
            dataIndex: "status",

            scopedSlots: {customRender: "status"}
        },
    ];

    // import moment from "moment";
    // import * as Util from "../common/util";

    export default {
        name: "Dashboard",
        components: {},
        data() {
            return {
                columns,
                drawer,
                group,
                patientin,
                data: [],
                Groupinfodata: [],
                selectedRowKeys: [],
                selectedRow: [],
                selectedDoctorRowKeys: [],
                selectedDoctorRow: [],
                punchindata: [],
                Groupinfo: {
                    self:[],
                    cooperation:[],
                has_groups:"",
                },
                pagination: {
                    pageSize: 8
                },
                popinfos: false,
                visible: false,
                Doctorvisible: false,
                popaddself: false,
                popaddcoop: false,
                popeditself: false,
                popeditcoop: false,
                Punchinvisible: false,
                search_text: "",
                loading: false,
                Doctordata: Storage.Doctordata,
                add: {
                    title: "",
                    interval_time: "",
                    interval_type: "",
                    is_default: "1",
                    ids: [],
                    uids: [],
                },
                edit: {
                    uid: "",
                    login_name: "",
                    password: "",
                    re_password: "",
                    name: "",
                    sex: "2",
                    mobile: "",
                },
            };
        },
        created() {
            // 获取第一页内容
            this.getpunchin(1, this.pagination.pageSize, "");
            // this.getpatient(1, this.pagination.pageSize, "");
            // this.doSearch(1, this.pagination.pageSize, "");
        },
        methods: {
            start() {
                this.loading = true;
                this.data = [];
                // ajax request after empty completing
                setTimeout(() => {
                    this.loading = false;
                    this.selectedRowKeys = [];
                }, 1000);
                this.doSearch(1, this.pagination.pageSize);
            },
            callback(key) {
                console.log(key);
            },
            async onSearch(text) {
                this.data = []
                this.search_text = text;
                this.doSearch(1, this.pagination.pageSize, text);
            },

            async onChange(pagination) {
                await this.doSearch(
                    this.search_text,
                    pagination.current - 1,
                    pagination.pageSize
                );
            },

            async onChanges(e) {
                console.log(e.target.value);
            },

            async onChangess(checkedValues) {
                console.log('checked = ', checkedValues);
                this.add.uids = checkedValues;
            },
            showModal(item) {
                console.log(item)
                this.popinfos = true;
            },
            showPunchinDrawer() {
                this.Punchinvisible = true;
            },
            addself() {

                this.add.name = "";
                this.add.uids = [];
                this.selectedRowKeys = [];
                this.selectedRow = [];
                this.selectedDoctorRowKeys = [];
                this.selectedDoctorRow = [];

                this.popaddself = true;
            },
            addhas_groups() {
                this.add.name = "";
                this.add.uids = [];
                this.selectedRowKeys = [];
                this.selectedRow = [];
                this.selectedDoctorRowKeys = [];
                this.selectedDoctorRow = [];
                this.popaddcoop = true;
            },
            editself(item) {

                console.log(item)
                this.edit.name = item.name;
                // this.edit.uids = item.uids;
                this.selectedRowKeys = [];
                this.selectedRow = [];
                this.selectedDoctorRowKeys = [];
                this.selectedDoctorRow = [];
                this.getGroupinfo(1, 20, "", item.id);
                this.popeditself = true;
            },
            edithas_groups(item) {
                this.add.name = "";
                this.add.uids = [];
                this.getGroupinfo(1, 20, "", item.id);
                this.selectedRowKeys = [];
                this.selectedRow = [];
                this.selectedDoctorRowKeys = [];
                this.selectedDoctorRow = [];
                this.popeditcoop = true;
            },
            async addcoopok() {
                // if (this.edit.login_name =="") {
                //     Modal.warning({
                //         title: "请输入用户名"
                //     });
                //     this.popinfos = true;
                //     return
                // }
                // if (this.edit.password != this.edit.re_password) {
                //     Modal.warning({
                //         title: "两次密码不一致"
                //     });
                //     this.popinfos = true;
                //     return
                // }
                let now = Date.now();
                let result = await this.$post("/api/admin/customerGroup/update", {
                    uid: Storage.uid,
                    token: Storage.token,
                    group_id: this.edit.group_id,
                    name: this.edit.name,
                    uids: this.selectedRowKeys,
                    t: now,

                });

                if (result.status === true) {
                    this.Groupinfodata = []
                    this.data = []
                    this.getGroupinfo(1, 20, "", this.edit.group_id);
                    await this.doSearch(1, this.pagination.pageSize, "");
                    Modal.info({
                        title: "更新成功"
                    });
                }
                this.visible = false;
                this.popinfos = false;
            },
            async addselfok() {
                // if (this.edit.login_name =="") {
                //     Modal.warning({
                //         title: "请输入用户名"
                //     });
                //     this.popinfos = true;
                //     return
                // }
                // if (this.edit.password != this.edit.re_password) {
                //     Modal.warning({
                //         title: "两次密码不一致"
                //     });
                //     this.popinfos = true;
                //     return
                // }
                let now = Date.now();
                let result = await this.$post("/api/admin/customerGroup/create", {
                    uid: Storage.uid,
                    token: Storage.token,
                    d_uid: this.add.d_uid,
                    save_value:{
                        name: this.add.name,
                        p_id: this.add.p_id,
                        more_info_ids: this.add.more_info_ids,
                        t: now,
                    },

                });

                if (result.status === true) {
                    this.add.group_id = result.data
                    await this.addPatient();
                    console.log('开始添加人员',this.add.group_id);

                }else{
                    Modal.info({
                        title: result.msg
                    });
                }

            },async editcoopok() {
                // if (this.edit.login_name =="") {
                //     Modal.warning({
                //         title: "请输入用户名"
                //     });
                //     this.popinfos = true;
                //     return
                // }
                // if (this.edit.password != this.edit.re_password) {
                //     Modal.warning({
                //         title: "两次密码不一致"
                //     });
                //     this.popinfos = true;
                //     return
                // }
                let now = Date.now();
                let result = await this.$post("/api/admin/customerGroup/update", {
                    uid: Storage.uid,
                    token: Storage.token,
                    group_id: this.edit.group_id,
                    name: this.edit.name,
                    uids: this.selectedRowKeys,
                    t: now,

                });

                if (result.status === true) {
                    this.Groupinfodata = []
                    this.data = []
                    this.getGroupinfo(1, 20, "", this.edit.group_id);
                    await this.doSearch(1, this.pagination.pageSize, "");
                    Modal.info({
                        title: "更新成功"
                    });
                }
                this.visible = false;
                this.popinfos = false;
            },
            async editselfok() {
                // if (this.edit.login_name =="") {
                //     Modal.warning({
                //         title: "请输入用户名"
                //     });
                //     this.popinfos = true;
                //     return
                // }
                // if (this.edit.password != this.edit.re_password) {
                //     Modal.warning({
                //         title: "两次密码不一致"
                //     });
                //     this.popinfos = true;
                //     return
                // }
                let now = Date.now();
                let result = await this.$post("/api/admin/customerGroup/create", {
                    uid: Storage.uid,
                    token: Storage.token,
                    d_uid: this.add.d_uid,
                    save_value:{
                        name: this.add.name,
                        p_id: this.add.p_id,
                        more_info_ids: this.add.more_info_ids,
                        t: now,
                    },

                });

                if (result.status === true) {
                    this.add.group_id = result.data

                    console.log('开始添加人员',this.add.group_id);

                }else{
                    Modal.info({
                        title: result.msg
                    });
                }

            },
            async addPatient() {


                let now = Date.now();
                let result = await this.$post("/api/admin/customerGroup/addCustomer", {
                    uid: Storage.uid,
                    token: Storage.token,
                    uids: this.selectedRowKeys,
                    group_id: this.add.group_id,
                    d_uid: this.add.d_uid,
                    t: now,
                });

                if (result.status === true) {
                    this.data = []
                    await this.doSearch(1, this.pagination.pageSize, "");
                    Modal.info({
                        title: "创建成功"
                    });
                }else{
                    Modal.info({
                        title: result.msg
                    });
                }
                this.visible = false;
                this.popaddself = false;
            },
            async getGroupinfo(page, limit, search, groupid) {
                this.loading = true;
                this.selectedRowKeys = [];
                console.log(Storage.uid)
                console.log(Storage.token)
                let now = Date.now();
                let result = await this.$get("/api/admin/customerGroup/getGroupAccount", {
                    params: {
                        token: Storage.token,
                        uid: Storage.uid,
                        page: page,
                        limit: limit,
                        search: search,
                        group_id: groupid,
                        t: now,
                    }
                });

                if (result.status === true) {
                    let data = [...this.data];
                    for (let i in result.data.list) {
                        let info = result.data.list[i];
                        // let offset = (parseInt(page) - 1) * limit + parseInt(i);
                        // console.log(offset)

                        data[i] = {
                            uid: info.uid,
                            login_name: info.login_name,
                            name: info.name,
                            sex: info.sex,
                            mobile: info.mobile,
                        };
                        this.selectedRowKeys.push(info.uid)
                        this.selectedRow.push(info)

                    }

                    // let pagination = {...this.pagination};
                    // pagination.total = result.data.total;
                    // this.pagination = pagination;
                    this.Groupinfodata = data;
                    console.log(this.Groupinfodata)
                    this.loading = false;
                }

                this.loading = false;
            },

            async getDoctorGroup(d_uid) {
                this.loading = true;
                this.data = [];
                // console.log(Storage.uid)
                // console.log(Storage.token)
                let now = Date.now();
                let result = await this.$get("/api/admin/customerGroup/list", {
                    params: {
                        token: Storage.token,
                        uid: Storage.uid,
                        d_uid: d_uid,
                        t: now,
                    }
                });

                if (result.status === true) {

                    // let data = [...this.data];
                    // for (let i in result.data) {
                    //     let info = result.data[i];
                    //     // let offset = (parseInt(page) - 1) * limit + parseInt(i);
                    //     // console.log(offset)
                    //
                    //     data[i] = {
                    //         id: info.id,
                    //         name: info.name,
                    //         is_publice: info.is_publice,
                    //         p_id: info.p_id,
                    //         status: info.status,
                    //         type: info.type,
                    //         uid: info.uid,
                    //         count: info.count,
                    //
                    //     };
                    // }

                    // let pagination = {...this.pagination};
                    // pagination.total = result.data.total;
                    // this.pagination = pagination;
                    this.Groupinfo = result.data;
                    this.add.d_uid = d_uid;
                    this.getpatient(1, this.pagination.pageSize, "","",d_uid);
                    console.log(this.Groupinfo);
                    console.log(this.add.d_uid);
                    this.loading = false;
                }

                this.loading = false;
            },
            async getpatient(page, limit, search, account_group_id, d_uid) {
                this.loading = true;
                this.data = [];
                // console.log(Storage.uid)
                // console.log(Storage.token)
                let now = Date.now();
                let result = await this.$get("/api/admin/customer/list", {
                    params: {
                        token: Storage.token,
                        uid: Storage.uid,
                        page: page,
                        limit: limit,
                        search: search,
                        account_group_id: account_group_id,
                        d_uid: d_uid,
                        t: now,
                    }
                });

                if (result.status === true) {
                    let data = [...this.data];
                    for (let i in result.data.list) {
                        let info = result.data.list[i];
                        let offset = (parseInt(page) - 1) * limit + parseInt(i);
                        // console.log(offset)

                        data[offset] = {
                            uid: info.uid,
                            name: info.name,
                            group_name: info.group_name,
                            login_ip: info.login_ip,
                            login_name: info.login_name,
                            login_time: moment(info.login_time * 1000).format("YYYY/MM/DD"),
                            // login_time: info.login_time,
                            mobile: info.mobile,
                            nike_name: info.nike_name,
                            sex: info.sex,
                            status: info.status,
                            d_uid: info.d_uid,
                            d_name: info.d_name,
                        };
                    }

                    let pagination = {...this.pagination};
                    pagination.total = result.data.total;
                    this.pagination = pagination;
                    this.data = data;
                    this.loading = false;
                }

                this.loading = false;
            },
            onSelectChange(selectedRowKeys,selectedRows) {
                this.selectedRowKeys = [];
                console.log('selectedRowKeys changed: ', selectedRowKeys);
                console.log('selectedRowKeys changed: ', selectedRows);
                this.selectedRowKeys = selectedRowKeys;
                this.selectedRow = selectedRows;
            },
            onSelectDoctorChange(selectedRowKeys,selectedRows) {
                this.selectedDoctorRowKeys = [];
                console.log('selectedRowKeys changed: ', selectedRowKeys);
                this.selectedDoctorRowKeys = selectedRowKeys;
                this.selectedDoctorRow = selectedRows;
            },
            showDrawer() {
                this.visible = true;
            },
            popok() {
                this.visible = true;
            },
            showDoctorDrawer() {
                this.Doctorvisible = true;
            },
            handleClick(e) {
                // console.log('click ', e);
                this.getDoctorGroup(e.key);
            },
            onClose() {
                this.visible = false;
                this.Doctorvisible = false;
                this.Punchinvisible = false;
            },
            async getpunchin(page, limit, search) {
                this.loading = true;
                this.punchindata = [];
                console.log(Storage.uid)
                console.log(Storage.token)
                let now = Date.now();
                let result = await this.$get("/api/admin/signInObject/list", {
                    params: {
                        token: Storage.token,
                        uid: Storage.uid,
                        page: page,
                        limit: limit,
                        search: search,
                        t: now,
                    }
                });

                if (result.status === true) {
                    let data = [...this.punchindata];
                    for (let i in result.data.list) {
                        let info = result.data.list[i];
                        // let offset = (parseInt(page) - 1) * limit + parseInt(i);
                        // console.log(offset)

                        data[i] = {
                            id: info.id,
                            title: info.title,
                            interval_type: info.interval_type,
                            interval_time: info.interval_time,
                            contents: info.contents,
                            status: info.status,
                            is_default: info.is_default,
                        };
                    }

                    let pagination = {...this.pagination};
                    pagination.total = result.data.total;
                    this.pagination = pagination;
                    this.punchindata = data;
                    this.loading = false;
                }

                this.loading = false;
            },
            async deleadmin(item) {
                var that = this;
                console.log(item);
                Modal.confirm({
                    title: "警告！",
                    content: "是否确认剔除该客户分组?",

                    onOk: async function () {

                        let result = await that.$post("/api/admin/account/delete", {

                            uid: Storage.uid,
                            token: Storage.token,
                            edit_uid: item.uid,
                            // notes: this.edit_pop.notes,
                            t: Date.now(),
                            // sign: Crypt.sign([
                            //     Storage.token,
                            //     this.edit_pop.id,
                            //     JSON.stringify(data),
                            //     this.edit_pop.notes,
                            //     this.$config.secret_key,
                            //     now
                            // ])
                        });
                        console.log(result);
                        if (result.status == true) {
                            console.log("准备弹窗！");
                            that.data = []
                            await that.doSearch(1, that.pagination.pageSize, "");

                            Modal.info({
                                title: "剔除成功"
                            });
                        }
                        if (result.status === false) {
                            // that.data = []
                            // await this.doSearch(this.page, "1", "", this.estatedefault, "");
                            Modal.info({
                                title: result.msg
                            });
                        }
                    }

                });


            },
            async addObject() {
                var that = this;
                console.log();
                that.add.ids=[];
                that.add.uids=[];
                that.add.ids = [...that.selectedDoctorRowKeys];
                console.log('ids: ', that.add.ids);
                Modal.confirm({
                    title: "警告！",
                    zIndex: 2000,
                    content: "是否确认增加该项目?",

                    onOk: async function () {

                        let result = await that.$post("/api/admin/accountSignInObject/add", {

                            uid: Storage.uid,
                            token: Storage.token,
                            ids: that.add.ids,
                            uids: that.add.uids,
                            // notes: this.edit_pop.notes,
                            t: Date.now(),
                            // sign: Crypt.sign([
                            //     Storage.token,
                            //     this.edit_pop.id,
                            //     JSON.stringify(data),
                            //     this.edit_pop.notes,
                            //     this.$config.secret_key,
                            //     now
                            // ])
                        });
                        console.log(result);
                        if (result.status == true) {
                            console.log("准备弹窗！");
                            // that.data = []
                            // await that.doSearch(1, that.pagination.pageSize, "");
                            that.getDoctorGroup(that.add.d_uid);
                            Modal.info({
                                title: "增加成功",
                                zIndex: 2000,
                            });
                            this.Punchinvisible = false;
                        }
                        if (result.status === false) {
                            // that.data = []
                            // await this.doSearch(this.page, "1", "", this.estatedefault, "");
                            Modal.info({
                                title: result.msg,
                                zIndex: 2000,
                            });
                            this.Punchinvisible = false;
                        }
                    }

                });


            },
        }
    };
</script>
<style scoped>
    .editable-row-operations a {
        margin-right: 8px;
    }

    #components-layout-demo-custom-trigger .trigger {
        font-size: 18px;
        line-height: 64px;
        padding: 0 24px;
        cursor: pointer;
        transition: color 0.3s;
    }

    #components-layout-demo-custom-trigger .trigger:hover {
        color: #1890ff;
    }

    #components-layout-demo-custom-trigger .logo {
        height: 32px;
        background: rgba(255, 255, 255, 0.2);
        margin: 16px;
    }

    .serach_input {
        width: 25vw;
        float: right;
        margin-top: 10px;
        margin-bottom: 10px;
        text-align: right;
        margin-right: 25px;
    }

    .pages {
        float: right;
        margin-top: 10px;
    }

    .toolsbar {
        display: block;
        width: 100%;
        height: 42px;
        background: #fff
    }
</style>
